//
//  ActionSheetDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/6/30.
//

import SwiftUI

struct ActionSheetDemo: View {
    
    @State var showActionSheet: Bool = false
    @State var actionSheetOption: ActionSheetOptions = .isMyPost
    
    enum ActionSheetOptions {
        case isMyPost
        case isOtherPost
    }
    
    var body: some View {
        
        VStack {
            HStack {
                Circle()
                    .frame(width: 30, height: 30)
                Text("@userName")
                Spacer()
                Button {
                    actionSheetOption = .isMyPost
                    showActionSheet.toggle()
                } label: {
                    Image(systemName: "ellipsis")
                }
                .accentColor(.primary)
                
            }
            .padding(.horizontal)
            
            Rectangle()
                .aspectRatio(1.0, contentMode: .fit)
        }
        
//        Button("Click me") {
//            showActionSheet.toggle()
//        }
        .actionSheet(isPresented: $showActionSheet) {
            getActionSheet()
        }
    }
    
    func getActionSheet() -> ActionSheet {
        
        
        let shareButton: ActionSheet.Button = .default(Text("Share")) {
            
        }
        let reportButton: ActionSheet.Button = .destructive(Text("Report"))
        let deleteButton: ActionSheet.Button = .destructive(Text("Delete"))
        let cancelButton: ActionSheet.Button = .cancel(Text("Cancel"))
        
        switch actionSheetOption {
        case .isMyPost:
            return ActionSheet(title: Text("What wound you like to do?"),
                                      message: nil,
                                                         buttons: [shareButton, reportButton, deleteButton, cancelButton]
                                      )
        case .isOtherPost:
            return ActionSheet(title: Text("What wound you like to do?"),
                                      message: nil,
                                                         buttons: [shareButton, reportButton, cancelButton]
                                      )
        }
        
        
        
//        return ActionSheet(title: Text("This is the title"))
        
        
//        let button1: ActionSheet.Button = .default(Text("Default"))
//        let button2: ActionSheet.Button = .destructive(Text("Destructive"))
//        let button3: ActionSheet.Button = .cancel(Text("Cancel"))
//        return ActionSheet(title: Text("This is the title"),
//        message: Text("This is the message"),
//                           buttons: [button1, button2, button3]
//        )
    }
    
}

#Preview {
    ActionSheetDemo()
}
